// -----------------------------------------------------------------------
// <copyright file="ContactPerson.cs" company="Imar.Spaanjaars.Com">
//   Copyright 2008 - 2009 - Imar.Spaanjaars.Com. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Diagnostics;
using Spaanjaars.Validation;

namespace Spaanjaars.ContactManager.BusinessEntities
{
	/// <summary>
	/// The ContactPerson class represents contact persons in the Contact Person Manager application.
	/// </summary>
	[DebuggerDisplay("Person: {FullName, nq} Type: ({Type, nq})")]
	public class ContactPerson : BusinessBase
	{
		#region Constructor(s)

		/// <summary>
		/// Initializes a new instance of the ContactPerson class.
		/// </summary>
		public ContactPerson()
		{
			Addresses = new AddressCollection();
			PhoneNumbers = new PhoneNumberCollection();
			EmailAddresses = new EmailAddressCollection();
			Type = PersonType.None;
		}

		#endregion

		#region Public Properties

		/// <summary>
		/// Gets or sets the unique ID of the contact person.
		/// </summary>
		[DataObjectFieldAttribute(true, true, false)]
		public override int Id { get; set; }

		/// <summary>
		/// Gets or sets the first name of the contact person.
		/// </summary>
		[NotNullOrEmpty(Key = "FirstNameNotEmpty")]
		public string FirstName { get; set; }

		/// <summary>
		/// Gets or sets the middle name of the contact person.
		/// </summary>
		[NotNullOrEmpty(Key = "LastNameNotEmpty")]
		public string LastName { get; set; }

		/// <summary>
		/// Gets or sets the last name of the contact person.
		/// </summary>
		public string MiddleName { get; set; }

		/// <summary>
		/// Gets or sets the date of birth of the contact person.
		/// </summary>
		[NotNullOrEmpty(Key = "DateOfBirhNotEmpty")]
		public DateTime DateOfBirth { get; set; }

		/// <summary>
		/// Gets or sets the type of the contact person.
		/// </summary>
		[EnumNotNoneAttribute(Key = "PersonTypeNotNone")]
		public PersonType Type { get; set; }

		/// <summary>
		/// Gets the full name of the contact person which is a combination of
		/// <see cref="FirstName" />, <see cref="MiddleName" /> and <see cref="LastName" />.
		/// </summary>
		public string FullName
		{
			get
			{
				string tempValue = FirstName;
				if (!string.IsNullOrEmpty(MiddleName))
				{
					tempValue += string.Format(" {0}", MiddleName);
				}

				tempValue += string.Format(" {0}", LastName);
				return tempValue;
			}
		}

		/// <summary>
		/// Gets or sets a collection of <see cref="Address" /> instances for the contact person.
		/// </summary>
		public AddressCollection Addresses { get; set; }

		/// <summary>
		/// Gets or sets a collection of <see cref="PhoneNumber" /> instances for the contact person.
		/// </summary>
		public PhoneNumberCollection PhoneNumbers { get; set; }

		/// <summary>
		/// Gets or sets a collection of <see cref="EmailAddress" /> instances for the contact person.
		/// </summary>
		public EmailAddressCollection EmailAddresses { get; set; }

		/// <summary>
		/// Determines whether the current instance meets all validation rules. 
		/// It does this by checking this instance and its collections like PhoneNumbers, Addresses and EmailAddresses.
		/// </summary>
		/// <returns>
		/// Returns <c>true</c> if the instance is valid, <c>false</c> otherwise.
		/// </returns>
		public override bool Validate()
		{
			bool baseValid = base.Validate();
			bool localValid = Addresses.Validate() && EmailAddresses.Validate() && PhoneNumbers.Validate();
			return baseValid && localValid;
		}
		#endregion
	}
}
